package org.tp;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.tp.Type;

/* tree implementing a type*/

public class Type {

	private Type left;
	private Type right;
	private EnumType type;	
	private Integer integer; // array size
	private String str;


	public Type(Type left, Type right, Integer i, EnumType type) {
		this.left=left;
		this.right=right;
		this.integer=i;
		this.type=type;
	}

	public Type(Type left, Type right, EnumType type) {
		this(left,right,0, type);
	}
	
	public Type(String left, EnumType type) {
		this(null, null,0, type);
		this.str = left;
	}

	public Type(EnumType type) {
		this(null,null,type);
	}

	public Type getLeft() {
		return left;
	}

	public void setLeft(Type left) {
		this.left = left;
	}

	public Type getRight() {
		return right;
	}

	public void setRight(Type right) {
		this.right = right;
	}

	public EnumType getEnumType() {
		return this.type;
	}
	public boolean compareTo(Type t){
    	switch (this.type) {
    	case CHAR:
    	case INT:
    	case FLOAT:
    	case STRING:
    	case BOOLEAN:
    		if (this.type == t.type)
                return true;
    		else return false;
    	case ARRAY:
    	case POINTER:
    		if (this.type == t.type)
                return this.left.compareTo(t.left);
    		else return false;
    	};
    	return false;	
    }
	 
	public String toString() {
		String result = new String();
		switch (type) {
		case INT:
		case CHAR:
		case STRING:
		case FLOAT:
		case BOOLEAN:
		case VIDE:
			result += type.toString();break;
		case ARRAY:result += left.toString() + "["+integer+"]"; break;
		case POINTER:result += "POINTER OF "+left.toString(); break;
		case STRUCT:
			result += "STRUCT(" + left.toString() + ")"; break;
		case TIMES:
			result += left.toString() + ", " + right.toString(); break;
		case ENUM:
			result += "enum {"+ str + "}"; break;
		case LIST:
			result += "ArrayList<" + left.toString()+ ">"; break;
		case MAP:
			result += "Map<"+left.toString() + ", " + right.toString() + ">"; break;
		case SET:
			result += "Set<" + left.toString() + ">"; break;
		case TYPESTRUCT:
			result += str; break;
			//case ERROR:result += "ERROR"; break;
		};
		return result;
	}
}